<template>
  <div>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">检查结果录入</i>
    </div>
    <el-divider></el-divider>

    <el-row :gutter="20">
      <el-col :span="6"><el-input v-model="finish_check_search.caseNumber" placeholder="请输入患者病历号"></el-input></el-col>
      <el-col :span="6"><el-input v-model="finish_check_search.realName" placeholder="请输入患者姓名"></el-input></el-col>
      <el-col :span="2"><el-button @click="selectpatients">搜索</el-button></el-col>
      <el-col :span="10"> </el-col>
    </el-row>
    <el-table style="margin-top:5px;width:80%" :data="finish_check_patient" size="mini">
      <el-table-column type="index" label="编号" width="80"></el-table-column>
      <el-table-column prop="realName" label="患者姓名" width="180"></el-table-column>
      <el-table-column prop="caseNumber" label="患者病历号"></el-table-column>
      <el-table-column prop="age" label="患者年龄" width="180"></el-table-column>
      <el-table-column prop="gender" label="患者性别" width="180"></el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <el-button size="mini" @click="selectCheckPatient(scope.$index,scope.row)">已完成检查</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top:5px;text-align:right;width:80%">
      <el-pagination
          :default-current-page="currPage"
          :page-size="pageSize"
          :total="totalCount"
          @current-change="finishCheckPatientChange"
      layout="prev,pager,next">
      </el-pagination>
    </div>
    <el-divider></el-divider>

    <el-table :data="finish_check_patient_select" style="width:80%;margin-top:20px;" size="mini"
      highlight-current-row @current-change="checkSelectionChange">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="techCode" label="检查编码"></el-table-column>
      <el-table-column prop="techName" label="检查名称"></el-table-column>
      <el-table-column prop="checkTime" label="检查时间" width="180"></el-table-column>
      <el-table-column prop="techPrice" label="单价" width="180"></el-table-column>
      <el-table-column prop="techType" label="费用分类" width="180"></el-table-column>
    </el-table>
    <div align="left">
      <el-tag >已选择的检查项目：{{ checkPatient.techName }}</el-tag>
    </div>
    <el-divider></el-divider>

    <el-descriptions title="选择输入检查结果的医生" :column="2" border style="margin-top:20px;width:50%">
      <el-descriptions-item label="科室选择">
        <el-select v-model="deptmentId" placeholder="选择科室" @change="getDepartMentEmployee">
          <el-option v-for="item in check_dept" :key="item.id" :label="item.deptName" :value="item.id"></el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="医生选择">
        <el-select v-model="employeeId" placeholder="选择医生">
          <el-option v-for="item in check_employee" :key="item.id" :label="item.realname" :value="item.id"></el-option>
        </el-select>
      </el-descriptions-item>
    </el-descriptions>

    <el-descriptions title="输入检查结果" :column="1" border style="margin-top:20px;width:80%">
      <el-descriptions-item label="检查结果" :labelStyle="{'width':'120px'}">
        <el-input type="textarea" :autosize="{minRows:2,maxRows:4}" v-model="checkResult" placeholder="请输入检查结果"></el-input>
      </el-descriptions-item>
    </el-descriptions>

    <div style="text-align:left;margin-top:20px">
      <el-button type="primary" @click="updateCheckInput">结果提交</el-button>
      <el-button type="primary" @click="clearCheckInput()">重置输入</el-button>
    </div>
  </div>
</template>
<script >
import qs from 'qs'
import {ElMessage} from "element-plus";
export default {
  data(){
    return {
      temp_select_check_patient:'',//记录最后点击的患者
      finish_check_search:{
        caseNumber:'',
        realName:''
      },
      checkResult:'',
      check_employee:[
        {
          id:1,
          realname:'华佗'
        }
      ],
      check_dept:[
        {
          id:'1',
          dept_name:'心电图科'
        }
      ],
      employeeId:'',
      deptmentId:'',
      checkPatient:{techName:''},
      //总条数
      totalCount:0,
      finish_check_patient_select:[],
      //表格的数据
      finish_check_patient:[],
      currPage:1,
      pageSize:5
    }
  },
  methods:{
    //检查结果录入
    updateCheckInput: async function (){
     debugger
      if(this.checkPatient.techName=='')
      {
        ElMessage({
          type:"warning",
          message:'请选择检查的项目'
        })
        return
      }
      //UPDATE  check_request
     // set inputcheck_employee_id=0,check_result=0 where id=0
      let url= 'http://localhost:8092/checkrequest/updateinpucheck'
      let value={
        id:this.checkPatient.rid,
        inputcheckEmployeeId:this.employeeId,
        checkResult:this.checkResult
      }
      await this.$axios.put(url,value).then(resp=>{
        ElMessage({
          type:'success',
          message:this.checkPatient.techName+":检查结果录入结束"
        })
        //---------------更新状态
        this.updateState()
        this.getPatientMedicaltechnology()
      })
    },


    //检查列表行发生改变时的事件对应的函数
    checkSelectionChange:function (row){
      //console.log(row);
      this.checkPatient=row
      console.log(this.checkPatient)
      // this.checkPatient.techName=row.techName
    },


    //分页插件，页码改变量的对应的函数
    finishCheckPatientChange:function (currPage){
      this.currPage=currPage
    },
    //得到患者
    selectpatients:function ()
    {

      let url=`http://localhost:8092/register/selectpatients/${this.currPage}`
      this.$axios.post(url,this.finish_check_search).then(resp=>{

        this.finish_check_patient=resp.data.result
        //console.log(this.finish_check_patient)
        this.totalCount=resp.data.total

        this.getPatientMedicaltechnology()

      })
    },
    //得到当前患者的检查的项目
    getPatientMedicaltechnology:function ()
    {
      let url='http://localhost:8092/medicaltechnology/selectbyregiserid'
      let value={
        registerId:this.finish_check_patient.length>0?this.finish_check_patient[0].id:0,
        checkState:'执行完成' //执行完成 已缴费
      }
      //this.finish_check_search
      this.$axios.post(url,value).then(resp=>{
        this.finish_check_patient_select=resp.data.result

      })
    },

    //得到科室下的医生
    getDepartMentEmployee:function ()
    {
      this.employeeId=''
      let url=`http://localhost:8092/register/selectbydepartmentid/${this.deptmentId}`
      this.$axios.get(url).then(resp=>{
        this.check_employee=resp.data.result
      })
    },
    //得到科室信息
    getRegisterDepart:async function (){
      let deptType='检查'
      let url=`http://localhost:8092/register/getdepartment/${deptType}`
     await this.$axios.get(url).then(resp=>{
        this.check_dept=resp.data.result
        console.log(this.check_dept)
      }).catch(error=>{
        console.log(error)
      })
    },
    //更新状态
    updateState:async function (){
      let ids=[];
      ids.push(this.checkPatient.rid)
      let url=`http://localhost:8092/checkrequest/updatestate/${ids}/4`
      await  this.$axios.get(url).then(resp=>{

      }).catch(error=>{
        console.log(error)
      })
    },
  },
  mounted() {
    this.getRegisterDepart()
  }
}
</script>